package com.matt.controller.web;


import com.matt.commons.model.StatusResponse;
import com.matt.domain.CreateStaff;
import com.matt.foundation.constant.RequestConstant;
import com.matt.foundation.utils.IpHelper;
import com.matt.service.remoteCall.SsoCallService;
import com.tuo51.components.redis.RedisService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping("/web/un_login")
@Api(tags ="Web登录")
@Slf4j
public class WebLoginController {

    @Autowired
    private SsoCallService ssoCallService;


    @PostMapping(value = "/phone_pass_login")
    @ResponseBody
    public StatusResponse phonePassLogin(String mobile, String password,@RequestHeader(required = false) String platformId, HttpServletRequest request){
        String ticket = ssoCallService.passLogin(mobile, password, IpHelper.getRequestIpAddr(request), 0,platformId);
        return StatusResponse.success(ticket);
    }

    //教师注册
    @PostMapping(value = "/create1")
    @ResponseBody
    public StatusResponse create1(@RequestBody CreateStaff createStaff){
        String response = ssoCallService.create1(createStaff);
        return StatusResponse.success(response);
    }

    @GetMapping("/modify_password")
    @ResponseBody
    public StatusResponse modifyPassword(@RequestHeader(RequestConstant.TICKET) String ticket, String oldPassword, String newPassword) {
        Map response = ssoCallService.resetPassword(ticket, oldPassword, newPassword);
        return StatusResponse.success(response);
    }


    @PostMapping("/forget_password")
    @ResponseBody
    public StatusResponse forget_password( String phone, String verifyCode,String newPassword) {
        String response = ssoCallService.forgetPassword( phone,verifyCode, newPassword);
        return StatusResponse.success(response);
    }



}
